
'''	
	This file is part of Roseena.
	
	Copyright (C) 2008	Mohamed Hazem <mohamed.hazem@student.guc.edu.eg>
	Copyright (C) 2008	Mostafa Hany <mostafa.hany@student.guc.edu.eg>

	
	Roseena is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Roseena is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Roseena.	If not, see <http://www.gnu.org/licenses/>.
'''

from PyQt4.QtGui import QWidget, QVBoxLayout, QHBoxLayout, QPlainTextEdit, QLineEdit, QPushButton, QTextEdit, QFont, QApplication, QDialog
from PyQt4.QtCore import SIGNAL
from Client import Client
import sys

HOST = "localhost"
PORT = 8000

class ClientWindow(QWidget):
	'''
	Client's window class
	'''

	def __init__(self):
		'''
		Constructor
		'''
		app = QApplication(sys.argv)

		QWidget.__init__(self)

		self.client = Client(HOST, PORT)

		self.requestEntryLine = QLineEdit()
		self.requestEntryLine.setFixedSize(300, 25)

		self.infoArea = QPlainTextEdit()
		self.infoArea.setReadOnly(True)

		font = QFont()
		font.setBold(True)

		self.infoArea.setFont(font)

		sendRequestButton = QPushButton("Send Request")
		self.connect(sendRequestButton, SIGNAL("clicked()"), self.sendRequest)

		horizontalBox = QHBoxLayout()
		verticalBox = QVBoxLayout()

		horizontalBox.addWidget(self.requestEntryLine)
		horizontalBox.addWidget(sendRequestButton)

		verticalBox.addLayout(horizontalBox)
		verticalBox.addWidget(self.infoArea)

		self.setLayout(verticalBox)
#		self.setFixedSize(400, 400)
		self.setGeometry(100,100,100,100)
		self.setWindowTitle("Client")
		self.show()

		sys.exit(app.exec_())

	def sendRequest(self):
		'''
		Method responsible for sending the HTTP request when the
		clicked() signal is emitted.
		'''
		self.client.issueRequest(self.requestEntryLine.text())
		self.infoArea.appendPlainText("Request " + "'" + self.requestEntryLine.text() + "'" + " Sent")
		self.requestEntryLine.clear()
